import React, { useState } from 'react'
import { Input, Button } from 'antd'
import { useDispatch } from 'react-redux'
import { addlist } from './store/todoSlice'

//添加数组 == 修改redux管理的数据
export default function Add() {

  let [title, setTitle] = useState('')

  let dispatch = useDispatch()

  return (
    <div>
      <Input value={title} onChange={(e) => {
        setTitle(e.target.value)
      }}

        suffix={<Button onClick={() => {
          //添加
          let obj = {
            id: new Date().getTime(),
            title,
            sed: false
          }
          //执行添加的方法
          //dispatch执行发送的action对象 通知reducer去修改
          dispatch(addlist(obj))
          setTitle('')
        }}>添加</Button>} />
    </div>
  )
}
